package Utils;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author dqthuc
 *
 */
public class Common {

	public static String makeSuccessXML() {
		return "<root value='true'/>";
	}
	public static String makeErrorXML(String mesage) {
		return "<root value='false' msg=\""+mesage+"\"/>";
	}
	/**
	 * <br/>[ Function ] Method print <br/> [ Description ] Print content
	 * string to screen with zip.
	 * 
	 * @param Response
	 * @param content
	 * @return file bean
	 */
	public static final void print(HttpServletRequest request,
			HttpServletResponse response, String content, String encodeType, String contentType, boolean cache) {
		try {
			response.setContentType(contentType);
			//if (!cache)
				response.setHeader("Cache-Control", "no-cache");
			ZipResponse.write(request, response, content, encodeType);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * <br/>[ Function ] Method print <br/> [ Description ] Print content
	 * string to client.
	 * 
	 * @param resp
	 * @param content
	 */
	public static final void print(HttpServletResponse response, String content, String contentType, boolean cache) {
		try {
			response.setContentType(contentType);
			//if (!cache)
				response.setHeader("Cache-Control", "no-cache");
			response.getWriter().print(content);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static String makeSuccessXML(String content) {
		return "<root value='true'>"+content+"</root>";
	}
	public static boolean checkImg(String file){
		String type = file.substring(file.lastIndexOf(".")+1,file.length()).toLowerCase();
		
		if(type.equals("jpg")||type.equals("jpeg")||type.equals("gif")||type.equals("png"))
			return true;
		return false;
	}
	
}
